package com.snail.poker.service.impl;

import com.snail.poker.dao.EquipmentDao;
import com.snail.poker.model.Equipment;
import com.snail.poker.service.EquipmentService;
import com.snail.poker.uitls.Constant;
import com.snail.poker.web.bean.PageBean;

public class EquipmentServiceImpl implements EquipmentService {
	private EquipmentDao equipmentDao;

	public EquipmentDao getEquipmentDao() {
		return equipmentDao;
	}

	public void setEquipmentDao(EquipmentDao equipmentDao) {
		this.equipmentDao = equipmentDao;
	}

	@Override
	public Equipment saveEquipment(Equipment equipment) throws Exception {
		// TODO Auto-generated method stub
		if (null == equipment) {
			throw new NullPointerException("输入有误！");
		}
		// 将登录的移动设备状态更改为在线
		equipment.setStatus(Constant.STATUS_ONLINE);
		this.equipmentDao.addEquipment(equipment);
		return equipment;
	}

	@Override
	public PageBean queryEquipment() {
		// TODO Auto-generated method stub
		return this.equipmentDao.queryEquipment();
	}

	@Override
	public boolean changeStatus(Equipment equipment, int status)
			throws Exception {
		// TODO Auto-generated method stub
		if (equipment.getStatus() == status) {
			throw new Exception("状态一致，无需变更.");
		}
		this.equipmentDao.changeStatus(equipment.getEquipmentSn(), status);
		// 如果传入的数据为离线状态，则返回true删除Session
		if (Constant.STATUS_OFFLINE == status) {
			return true;
		}
		return false;
	}
}
